﻿@model Product
@{
    var set = Model != null ? new HashSet<int>(Model.RelatedProducts.Select(p => p.Id)) : new HashSet<int>();
    int thisId = 0;
    if (Model != null) { thisId = Model.Id; }
}

<div class="editor-label">
    <label for="RelatedInput">Related Products</label>
</div>
<div class="editor-field">
    <select name="RelatedInput" id="RelatedInput" multiple="multiple">
        <optgroup label="Modules">
            @foreach (var m in ContextManager.CurrentDb.Modules.Where(m => m.Id != thisId).ToList().Where(m => !m.IsPast))
            {
                <option @if (set.Contains(m.Id)) { <text>selected="selected"</text> } value="@m.Id">@m.Title</option>
            }
        </optgroup>
        <optgroup label="Videos">
            @foreach (var v in ContextManager.CurrentDb.Videos.Where(v => v.Id != thisId))
            {
                <option @if (set.Contains(v.Id)) { <text>selected="selected"</text> } value="@v.Id">@v.Title</option>
            }
        </optgroup>
    </select>
</div>

